package com.itheima.servlet.test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@WebServlet("/stu/*")
public class ServletDemo extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //接收浏览器输入的数据
        String username = req.getParameter("username");
        String age = req.getParameter("age");
        String score = req.getParameter("score");

        //存储数据到本地
        BufferedWriter bw = new BufferedWriter(new FileWriter("\\day07_s                                                                                                                                                                                                                                       ervlet\\stu.txt", true));
        bw.write(username + "," + age + "," + score);
        bw.newLine();
        bw.close();

        //给浏览器响应
        PrintWriter pw = resp.getWriter();
        pw.println("save success");
        pw.close();
    }
}
